package com.pfs.internal.timestamp.actions;

import java.util.List;
import java.util.Map;

import org.apache.struts2.ServletActionContext;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.pfs.internal.timestamp.entities.CardHolder;
import com.pfs.internal.timestamp.repositories.CardHolderRepository;

@SuppressWarnings("serial")
public class EmployeesAction extends ActionSupport {
	private List<CardHolder> cardHolders;
	Map<String, Object> session = ActionContext.getContext().getSession();

	@Action(value = "ts-employees-all-list", results = { @Result(name = "success", type = "json") })
	public String listPfsEmployees() {
		WebApplicationContext context = WebApplicationContextUtils.getRequiredWebApplicationContext(ServletActionContext.getServletContext());
		CardHolderRepository cardHolderRepository = (CardHolderRepository) context.getBean("cardHolderRepository");
		cardHolders = cardHolderRepository.findAllPfs();
		System.out.println(cardHolders.size());
		return SUCCESS;
	}
	
	@Action(value = "ts-employees-no-hand-reg-list", results = { @Result(name = "success", type = "json") })
	public String listEmployeesNoHandReg() {
//		WebApplicationContext context = WebApplicationContextUtils.getRequiredWebApplicationContext(ServletActionContext.getServletContext());
//		CardHolderRepository cardHolderRepository = (CardHolderRepository) context.getBean("cardHolderRepository");
		//cardHolders = cardHolderRepository.findAllIn();
		//System.out.println(devices.size());
		return SUCCESS;
	}

	public Map<String, Object> getSession() {
		return session;
	}

	public void setSession(Map<String, Object> session) {
		this.session = session;
	}

	public List<CardHolder> getCardHolders() {
		return cardHolders;
	}

	public void setCardHolders(List<CardHolder> cardHolders) {
		this.cardHolders = cardHolders;
	}

}
